﻿using System;
using Caliburn.Micro;

namespace OPSYS_Schematic.UIInfrastructure
{
    /// <summary>
    /// A menu part for various implementations of <see cref="IMenuPart"/>.
    /// </summary>
    public class MenuPart : PartBase, IMenuPart, IObservableParent<IMenuPart>
    {
        private readonly IObservableCollection<IMenuPart> items = new BindableCollection<IMenuPart>();
        private bool _isCheckable;
        private bool _isChecked;
        private bool _isSeparator;

        public MenuPart()
        {
        }

        public MenuPart(string name)
            : base(name)
        {
        }

        public MenuPart(string name, Action<PartBase> execute, Func<bool> canExecute = null)
            : base(name, execute, canExecute)
        {
        }

        #region IMenuPart Members

        public bool IsSeparator
        {
            get { return _isSeparator; }
            protected set
            {
                _isSeparator = value;
                NotifyOfPropertyChange(() => IsSeparator);
            }
        }

        public bool IsCheckable
        {
            get { return _isCheckable; }
            set
            {
                _isCheckable = value;
                NotifyOfPropertyChange(() => IsCheckable);
            }
        }

        public bool IsChecked
        {
            get { return _isChecked; }
            set
            {
                _isChecked = value;
                NotifyOfPropertyChange(() => IsChecked);
            }
        }

        #endregion

        #region IObservableParent<IMenuPart> Members

        IObservableCollection<IMenuPart> IObservableParent<IMenuPart>.Items
        {
            get { return items; }
        }

        #endregion
    }
}